@@ -37,7 +37,7 @@ |
||
37 | 37 |
<ConfirmationsSetting value="0" id="Add" /> |
38 | 38 |
<ConfirmationsSetting value="0" id="Remove" /> |
39 | 39 |
</component> |
40 |
- <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="JDK" project-jdk-type="JavaSDK"> |
|
40 |
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="JDK" project-jdk-type="JavaSDK"> |
|
41 | 41 |
<output url="file://$PROJECT_DIR$/build/classes" /> |
42 | 42 |
</component> |
43 | 43 |
<component name="ProjectType"> |
@@ -98,12 +98,6 @@ |
||
98 | 98 |
android:screenOrientation="portrait"/> |
99 | 99 |
|
100 | 100 |
<activity |
101 |
- android:name=".printer.PrinterSettingActivity" |
|
102 |
- android:configChanges="keyboardHidden|orientation|screenSize" |
|
103 |
- android:label="@string/app_name" |
|
104 |
- android:screenOrientation="portrait"/> |
|
105 |
- |
|
106 |
- <activity |
|
107 | 101 |
android:name=".activities.AboutUsActivity" |
108 | 102 |
android:configChanges="keyboardHidden|orientation|screenSize" |
109 | 103 |
android:label="@string/app_name" |
@@ -150,19 +144,6 @@ |
||
150 | 144 |
|
151 | 145 |
<service android:name=".service.OrderDealService"/> |
152 | 146 |
|
153 |
- <service android:name=".printer.PrinterService"/> |
|
154 |
- |
|
155 |
- <service |
|
156 |
- android:name="com.gprinter.service.GpPrintService" |
|
157 |
- android:label="GpPrintService" |
|
158 |
- android:process=":remote" |
|
159 |
- android:enabled="true" |
|
160 |
- android:exported="true"> |
|
161 |
- <intent-filter> |
|
162 |
- <action android:name="com.gprinter.aidl.GpPrintService" /> |
|
163 |
- </intent-filter> |
|
164 |
- </service> |
|
165 |
- |
|
166 | 147 |
</application> |
167 | 148 |
|
168 | 149 |
</manifest> |
@@ -1,100 +0,0 @@ |
||
1 |
-package ai.pai.lensman.printer; |
|
2 |
- |
|
3 |
-import android.bluetooth.BluetoothDevice; |
|
4 |
-import android.content.Context; |
|
5 |
-import android.view.LayoutInflater; |
|
6 |
-import android.view.View; |
|
7 |
-import android.view.ViewGroup; |
|
8 |
-import android.widget.BaseAdapter; |
|
9 |
-import android.widget.TextView; |
|
10 |
- |
|
11 |
-import java.util.ArrayList; |
|
12 |
- |
|
13 |
-import ai.pai.lensman.R; |
|
14 |
-import ai.pai.lensman.db.Preferences; |
|
15 |
- |
|
16 |
-/** |
|
17 |
- * Created by chengzhenyu on 2016/9/1. |
|
18 |
- */ |
|
19 |
- |
|
20 |
-public class BluetoothDeviceListAdapter extends BaseAdapter { |
|
21 |
- |
|
22 |
- private LayoutInflater inflater; |
|
23 |
- private ArrayList<BluetoothDevice> deviceList; |
|
24 |
- |
|
25 |
- public BluetoothDeviceListAdapter(Context context){ |
|
26 |
- inflater = LayoutInflater.from(context); |
|
27 |
- } |
|
28 |
- |
|
29 |
- public void setDeviceList(ArrayList<BluetoothDevice> newDeviceList){ |
|
30 |
- this.deviceList = newDeviceList; |
|
31 |
- notifyDataSetChanged(); |
|
32 |
- } |
|
33 |
- |
|
34 |
- public ArrayList<BluetoothDevice> getDeviceList(){ |
|
35 |
- return deviceList; |
|
36 |
- } |
|
37 |
- |
|
38 |
- public void addDevice(BluetoothDevice device){ |
|
39 |
- if(this.deviceList==null){ |
|
40 |
- this.deviceList = new ArrayList<>(); |
|
41 |
- } |
|
42 |
- if(!this.deviceList.contains(device)){ |
|
43 |
- this.deviceList.add(device); |
|
44 |
- } |
|
45 |
- notifyDataSetChanged(); |
|
46 |
- } |
|
47 |
- |
|
48 |
- @Override |
|
49 |
- public int getCount() { |
|
50 |
- if(this.deviceList==null){ |
|
51 |
- return 0; |
|
52 |
- } |
|
53 |
- return this.deviceList.size(); |
|
54 |
- } |
|
55 |
- |
|
56 |
- @Override |
|
57 |
- public Object getItem(int i) { |
|
58 |
- return this.deviceList.get(i); |
|
59 |
- } |
|
60 |
- |
|
61 |
- @Override |
|
62 |
- public long getItemId(int i) { |
|
63 |
- return 1000+ i; |
|
64 |
- } |
|
65 |
- |
|
66 |
- @Override |
|
67 |
- public View getView(int position, View convertView, ViewGroup viewGroup) { |
|
68 |
- ViewHolder holder; |
|
69 |
- if(convertView==null){ |
|
70 |
- convertView = inflater.inflate(R.layout.layout_bt_device_list_item,viewGroup,false); |
|
71 |
- holder = new ViewHolder(); |
|
72 |
- holder.deviceMac =(TextView) convertView.findViewById(R.id.tv_device_mac); |
|
73 |
- holder.deviceName =(TextView) convertView.findViewById(R.id.tv_device_name); |
|
74 |
- holder.deviceStatus =(TextView) convertView.findViewById(R.id.tv_device_status); |
|
75 |
- convertView.setTag(holder); |
|
76 |
- }else{ |
|
77 |
- holder = (ViewHolder) convertView.getTag(); |
|
78 |
- } |
|
79 |
- BluetoothDevice device = deviceList.get(position); |
|
80 |
- holder.deviceName.setText(device.getName()); |
|
81 |
- holder.deviceMac.setText(device.getAddress()); |
|
82 |
- if(device.getAddress().equals(Preferences.getInstance().getPrinterMac())){ |
|
83 |
- if(Preferences.getInstance().isPrinterConnected()){ |
|
84 |
- holder.deviceStatus.setText(R.string.bt_connected); |
|
85 |
- }else{ |
|
86 |
- holder.deviceStatus.setText(R.string.click_to_connect); |
|
87 |
- } |
|
88 |
- }else{ |
|
89 |
- holder.deviceStatus.setText(""); |
|
90 |
- } |
|
91 |
- return convertView; |
|
92 |
- } |
|
93 |
- |
|
94 |
- public static class ViewHolder{ |
|
95 |
- |
|
96 |
- public TextView deviceName; |
|
97 |
- public TextView deviceMac; |
|
98 |
- public TextView deviceStatus; |
|
99 |
- } |
|
100 |
-} |
@@ -1,179 +0,0 @@ |
||
1 |
-package ai.pai.lensman.printer; |
|
2 |
- |
|
3 |
-import android.app.Service; |
|
4 |
-import android.bluetooth.BluetoothDevice; |
|
5 |
-import android.content.ComponentName; |
|
6 |
-import android.content.Context; |
|
7 |
-import android.content.Intent; |
|
8 |
-import android.content.ServiceConnection; |
|
9 |
-import android.os.Binder; |
|
10 |
-import android.os.IBinder; |
|
11 |
-import android.util.Base64; |
|
12 |
-import android.util.Log; |
|
13 |
- |
|
14 |
-import com.android.common.utils.LogHelper; |
|
15 |
-import com.gprinter.aidl.GpService; |
|
16 |
-import com.gprinter.command.EscCommand; |
|
17 |
-import com.gprinter.command.GpCom; |
|
18 |
-import com.gprinter.io.PortParameters; |
|
19 |
-import com.gprinter.service.GpPrintService; |
|
20 |
- |
|
21 |
-import org.apache.commons.lang.ArrayUtils; |
|
22 |
- |
|
23 |
-import java.util.Vector; |
|
24 |
- |
|
25 |
-import ai.pai.lensman.R; |
|
26 |
-import ai.pai.lensman.db.Preferences; |
|
27 |
- |
|
28 |
- |
|
29 |
-public class PrinterService extends Service { |
|
30 |
- |
|
31 |
- private GpService mGpService; |
|
32 |
- private GpServiceConnection conn = null; |
|
33 |
- |
|
34 |
- public static final int ERROR_CODE_PRINTER_SERVICE_OFF = 1000; |
|
35 |
- public static final int ERROR_CODE_PRINTER_SERVICE_EXCEPTION = 2000; |
|
36 |
- |
|
37 |
- private static final String TAG = "PrinterService"; |
|
38 |
- |
|
39 |
- |
|
40 |
- class GpServiceConnection implements ServiceConnection { |
|
41 |
- @Override |
|
42 |
- public void onServiceDisconnected(ComponentName name) { |
|
43 |
- Log.i(TAG, "onServiceDisconnected() called"); |
|
44 |
- mGpService = null; |
|
45 |
- } |
|
46 |
- |
|
47 |
- @Override |
|
48 |
- public void onServiceConnected(ComponentName name, IBinder service) { |
|
49 |
- Log.i(TAG, "onServiceConnected() called"); |
|
50 |
- mGpService = GpService.Stub.asInterface(service); |
|
51 |
- } |
|
52 |
- } |
|
53 |
- |
|
54 |
- @Override |
|
55 |
- public void onCreate() { |
|
56 |
- super.onCreate(); |
|
57 |
- } |
|
58 |
- |
|
59 |
- @Override |
|
60 |
- public IBinder onBind(Intent intent) { |
|
61 |
- return new PrintServiceBinder(); |
|
62 |
- } |
|
63 |
- |
|
64 |
- @Override |
|
65 |
- public int onStartCommand(Intent intent, int flags, int startId) { |
|
66 |
- if(mGpService == null){ |
|
67 |
- startAndBindPrintService(); |
|
68 |
- } |
|
69 |
- return super.onStartCommand(intent, flags, startId); |
|
70 |
- } |
|
71 |
- |
|
72 |
- @Override |
|
73 |
- public void onDestroy() { |
|
74 |
- super.onDestroy(); |
|
75 |
- if (conn != null) { |
|
76 |
- unbindService(conn); |
|
77 |
- } |
|
78 |
- } |
|
79 |
- |
|
80 |
- |
|
81 |
- private void startAndBindPrintService() { |
|
82 |
- Intent intent = new Intent(this, GpPrintService.class); |
|
83 |
- startService(intent); |
|
84 |
- conn = new GpServiceConnection(); |
|
85 |
- bindService(intent, conn, Context.BIND_AUTO_CREATE); |
|
86 |
- } |
|
87 |
- |
|
88 |
- public String queryPrinterStatus() { |
|
89 |
- String str; |
|
90 |
- try { |
|
91 |
- int status = mGpService.queryPrinterStatus(0, 10000); |
|
92 |
- if (status == GpCom.STATE_NO_ERR) { |
|
93 |
- str = "打印机正常"; |
|
94 |
- Preferences.getInstance().setPrinterConnected(true); |
|
95 |
- } else { |
|
96 |
- Preferences.getInstance().setPrinterConnected(false); |
|
97 |
- str = "打印机 "; |
|
98 |
- if ((byte) (status & GpCom.STATE_OFFLINE) > 0) { |
|
99 |
- str += "脱机"; |
|
100 |
- } |
|
101 |
- if ((byte) (status & GpCom.STATE_PAPER_ERR) > 0) { |
|
102 |
- str += "缺纸"; |
|
103 |
- } |
|
104 |
- if ((byte) (status & GpCom.STATE_COVER_OPEN) > 0) { |
|
105 |
- str += "打印机开盖"; |
|
106 |
- } |
|
107 |
- if ((byte) (status & GpCom.STATE_ERR_OCCURS) > 0) { |
|
108 |
- str += "打印机出错"; |
|
109 |
- } |
|
110 |
- if ((byte) (status & GpCom.STATE_TIMES_OUT) > 0) { |
|
111 |
- str += "查询超时"; |
|
112 |
- } |
|
113 |
- } |
|
114 |
- |
|
115 |
- } catch (Exception e1) { |
|
116 |
- str = getString(R.string.printer_status_query_fail); |
|
117 |
- } |
|
118 |
- return str; |
|
119 |
- } |
|
120 |
- |
|
121 |
- public int printQR(String qrCodeStr) { |
|
122 |
- if(mGpService==null){ |
|
123 |
- return ERROR_CODE_PRINTER_SERVICE_OFF; |
|
124 |
- } |
|
125 |
- EscCommand esc = new EscCommand(); |
|
126 |
- /*打印文字*/ |
|
127 |
- esc.addSelectPrintModes(EscCommand.FONT.FONTA, EscCommand.ENABLE.OFF, EscCommand.ENABLE.OFF, |
|
128 |
- EscCommand.ENABLE.OFF, EscCommand.ENABLE.OFF);//取消倍高倍宽 |
|
129 |
- esc.addSelectJustification(EscCommand.JUSTIFICATION.CENTER);//设置打印左对齐 |
|
130 |
- esc.addText("拍爱\n"); // 打印文字 |
|
131 |
- esc.addPrintAndLineFeed(); |
|
132 |
- /*QRCode命令打印 |
|
133 |
- 此命令只在支持QRCode命令打印的机型才能使用。 |
|
134 |
- 在不支持二维码指令打印的机型上,则需要发送二维条码图片 |
|
135 |
- */ |
|
136 |
- esc.addSelectErrorCorrectionLevelForQRCode((byte) 0x31); //设置纠错等级 |
|
137 |
- esc.addSelectSizeOfModuleForQRCode((byte)8);//设置qrcode模块大小 |
|
138 |
- esc.addStoreQRCodeData(qrCodeStr);//设置qrcode内容 |
|
139 |
- esc.addSelectJustification(EscCommand.JUSTIFICATION.CENTER);//设置打印中心对齐 |
|
140 |
- esc.addPrintQRCode();//打印QRCode |
|
141 |
- esc.addPrintAndFeedLines((byte) 1); |
|
142 |
- |
|
143 |
- Vector<Byte> datas = esc.getCommand(); //发送数据 |
|
144 |
- Byte[] Bytes = datas.toArray(new Byte[datas.size()]); |
|
145 |
- byte[] bytes = ArrayUtils.toPrimitive(Bytes); |
|
146 |
- String str = Base64.encodeToString(bytes, Base64.DEFAULT); |
|
147 |
- int rel; |
|
148 |
- try { |
|
149 |
- rel = mGpService.sendEscCommand(0, str); |
|
150 |
- } catch (Exception e) { |
|
151 |
- rel = ERROR_CODE_PRINTER_SERVICE_EXCEPTION; |
|
152 |
- } |
|
153 |
- return rel; |
|
154 |
- } |
|
155 |
- |
|
156 |
- public int connectPrinter(BluetoothDevice device) { |
|
157 |
- if(mGpService==null){ |
|
158 |
- return ERROR_CODE_PRINTER_SERVICE_OFF; |
|
159 |
- } |
|
160 |
- int code ; |
|
161 |
- try { |
|
162 |
- code = mGpService.openPort(0, PortParameters.BLUETOOTH, device.getAddress(), 0); |
|
163 |
- LogHelper.d(TAG,"open port return code ="+code); |
|
164 |
- } catch (Exception e) { |
|
165 |
- LogHelper.e(TAG,"connectPrinter open port error "+e); |
|
166 |
- code = ERROR_CODE_PRINTER_SERVICE_EXCEPTION; |
|
167 |
- } |
|
168 |
- return code; |
|
169 |
- } |
|
170 |
- |
|
171 |
- public class PrintServiceBinder extends Binder { |
|
172 |
- |
|
173 |
- public PrinterService getService(){ |
|
174 |
- return PrinterService.this; |
|
175 |
- } |
|
176 |
- |
|
177 |
- } |
|
178 |
- |
|
179 |
-} |
@@ -1,170 +0,0 @@ |
||
1 |
-package ai.pai.lensman.printer; |
|
2 |
- |
|
3 |
-import android.app.Activity; |
|
4 |
-import android.bluetooth.BluetoothAdapter; |
|
5 |
-import android.bluetooth.BluetoothDevice; |
|
6 |
-import android.content.Intent; |
|
7 |
-import android.os.Bundle; |
|
8 |
-import android.os.Handler; |
|
9 |
-import android.support.annotation.Nullable; |
|
10 |
-import android.text.TextUtils; |
|
11 |
-import android.view.View; |
|
12 |
-import android.widget.AdapterView; |
|
13 |
-import android.widget.ImageView; |
|
14 |
-import android.widget.ListView; |
|
15 |
-import android.widget.TextView; |
|
16 |
-import android.widget.Toast; |
|
17 |
-import android.widget.ToggleButton; |
|
18 |
- |
|
19 |
-import com.android.common.utils.DeviceUtils; |
|
20 |
- |
|
21 |
-import java.util.ArrayList; |
|
22 |
-import java.util.List; |
|
23 |
- |
|
24 |
-import ai.pai.lensman.R; |
|
25 |
-import ai.pai.lensman.base.BaseActivity; |
|
26 |
-import ai.pai.lensman.qrcode.QRCreateUtils; |
|
27 |
-import butterknife.BindView; |
|
28 |
-import butterknife.ButterKnife; |
|
29 |
-import butterknife.OnCheckedChanged; |
|
30 |
-import butterknife.OnClick; |
|
31 |
- |
|
32 |
-public class PrinterSettingActivity extends BaseActivity implements PrinterSettingContract.View,AdapterView.OnItemClickListener { |
|
33 |
- |
|
34 |
- @BindView(R.id.listview_bt_devices) ListView btDevicesList; |
|
35 |
- @BindView(R.id.tv_printer_status) TextView printerStatusText; |
|
36 |
- @BindView(R.id.tv_bluetooth_status) TextView bluetoothStatusText; |
|
37 |
- @BindView(R.id.tb_bluetooth_switch) ToggleButton btSwitchToggle; |
|
38 |
- @BindView(R.id.iv_qrcode) ImageView qrCodeImg; |
|
39 |
- |
|
40 |
- private BluetoothDeviceListAdapter deviceAdapter; |
|
41 |
- private PrinterSettingContract.Presenter presenter; |
|
42 |
- |
|
43 |
- public static final int REQUEST_ENABLE_BT = 2; |
|
44 |
- public static final int REQUEST_CONNECT_DEVICE = 3; |
|
45 |
- |
|
46 |
- private String qrcode; |
|
47 |
- |
|
48 |
- @Override |
|
49 |
- protected void onCreate(@Nullable Bundle savedInstanceState) { |
|
50 |
- super.onCreate(savedInstanceState); |
|
51 |
- setContentView(R.layout.activity_printer_setting); |
|
52 |
- unbinder = ButterKnife.bind(this); |
|
53 |
- qrcode = getIntent().getStringExtra("qrcode"); |
|
54 |
- if(TextUtils.isEmpty(qrcode)){ |
|
55 |
- finish(); |
|
56 |
- return; |
|
57 |
- } |
|
58 |
- try{ |
|
59 |
- qrCodeImg.setImageBitmap(QRCreateUtils.Create2DCode("http://xfoto.com.cn/s/"+qrcode, |
|
60 |
- DeviceUtils.dip2px(this,240))); |
|
61 |
- }catch (Exception e){ |
|
62 |
- e.printStackTrace(); |
|
63 |
- } |
|
64 |
- |
|
65 |
- deviceAdapter = new BluetoothDeviceListAdapter(this); |
|
66 |
- btDevicesList.setAdapter(deviceAdapter); |
|
67 |
- btDevicesList.setOnItemClickListener(this); |
|
68 |
- presenter = new PrinterSettingPresenter(this,this); |
|
69 |
- } |
|
70 |
- |
|
71 |
- @Override |
|
72 |
- protected void onResume() { |
|
73 |
- super.onResume(); |
|
74 |
- presenter.start(); |
|
75 |
- } |
|
76 |
- |
|
77 |
- @Override |
|
78 |
- protected void onDestroy() { |
|
79 |
- presenter.stop(); |
|
80 |
- super.onDestroy(); |
|
81 |
- } |
|
82 |
- |
|
83 |
- @Override |
|
84 |
- public void onBluetoothEnabled() { |
|
85 |
- btSwitchToggle.setChecked(true); |
|
86 |
- bluetoothStatusText.setText(R.string.bt_is_enabled); |
|
87 |
- } |
|
88 |
- |
|
89 |
- @Override |
|
90 |
- public void onBluetoothDisabled() { |
|
91 |
- btSwitchToggle.setChecked(false); |
|
92 |
- bluetoothStatusText.setText(R.string.bt_is_disabled); |
|
93 |
- } |
|
94 |
- |
|
95 |
- |
|
96 |
- @Override |
|
97 |
- public void onPrinterStatusFetched(String msg) { |
|
98 |
- printerStatusText.setText(msg); |
|
99 |
- deviceAdapter.notifyDataSetChanged(); |
|
100 |
- } |
|
101 |
- |
|
102 |
- |
|
103 |
- @Override |
|
104 |
- public void onNewDeviceDiscovered(BluetoothDevice device) { |
|
105 |
- deviceAdapter.addDevice(device); |
|
106 |
- } |
|
107 |
- |
|
108 |
- |
|
109 |
- @Override |
|
110 |
- public void onPairedDeviceDiscovered(List<BluetoothDevice> devices) { |
|
111 |
- if(devices==null|| devices.size()==0){ |
|
112 |
- return; |
|
113 |
- } |
|
114 |
- deviceAdapter.setDeviceList((ArrayList<BluetoothDevice>)devices); |
|
115 |
- } |
|
116 |
- |
|
117 |
- |
|
118 |
- @Override |
|
119 |
- public void showToast(String msg) { |
|
120 |
- Toast.makeText(this,msg,Toast.LENGTH_SHORT).show(); |
|
121 |
- } |
|
122 |
- |
|
123 |
- @OnClick(R.id.tv_printer_status) |
|
124 |
- void checkStatus(){ |
|
125 |
- showToast(getString(R.string.query_processing)); |
|
126 |
- presenter.queryPrinterStatus(); |
|
127 |
- } |
|
128 |
- |
|
129 |
- @OnClick(R.id.btn_print_qr) |
|
130 |
- void printerQR(){ |
|
131 |
- presenter.printQR("http://xfoto.com.cn/s/"+qrcode); |
|
132 |
- } |
|
133 |
- |
|
134 |
- @OnClick(R.id.title_bar_back_layout) |
|
135 |
- void back(){ |
|
136 |
- finish(); |
|
137 |
- } |
|
138 |
- |
|
139 |
- @OnCheckedChanged(R.id.tb_bluetooth_switch) |
|
140 |
- void switchBluetooth(){ |
|
141 |
- if(!presenter.queryBluetoothStatus()){ |
|
142 |
- Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); |
|
143 |
- startActivityForResult(enableIntent, REQUEST_ENABLE_BT); |
|
144 |
- }else{ |
|
145 |
- BluetoothAdapter.getDefaultAdapter().disable(); |
|
146 |
- onBluetoothDisabled(); |
|
147 |
- } |
|
148 |
- } |
|
149 |
- |
|
150 |
- @Override |
|
151 |
- protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
|
152 |
- super.onActivityResult(requestCode, resultCode, data); |
|
153 |
- if(resultCode == Activity.RESULT_OK){ |
|
154 |
- if(requestCode == REQUEST_ENABLE_BT){ |
|
155 |
- onBluetoothEnabled(); |
|
156 |
- onPairedDeviceDiscovered(presenter.queryPairedDevices()); |
|
157 |
- presenter.discoverNewDevices(); |
|
158 |
- presenter.queryPrinterStatus(); |
|
159 |
- }else if(requestCode == REQUEST_CONNECT_DEVICE){ |
|
160 |
- |
|
161 |
- } |
|
162 |
- } |
|
163 |
- } |
|
164 |
- |
|
165 |
- @Override |
|
166 |
- public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { |
|
167 |
- presenter.connectPrinter(deviceAdapter.getDeviceList().get(i)); |
|
168 |
- } |
|
169 |
- |
|
170 |
-} |
@@ -1,33 +0,0 @@ |
||
1 |
-package ai.pai.lensman.printer; |
|
2 |
- |
|
3 |
-import android.bluetooth.BluetoothDevice; |
|
4 |
- |
|
5 |
-import java.util.List; |
|
6 |
- |
|
7 |
-/** |
|
8 |
- * Created by chengzhenyu on 2016/9/1. |
|
9 |
- */ |
|
10 |
- |
|
11 |
-public class PrinterSettingContract { |
|
12 |
- |
|
13 |
- public interface Presenter{ |
|
14 |
- void start(); |
|
15 |
- void stop(); |
|
16 |
- void queryPrinterStatus(); |
|
17 |
- void printQR(String qrCodeStr); |
|
18 |
- boolean queryBluetoothStatus(); |
|
19 |
- List<BluetoothDevice> queryPairedDevices(); |
|
20 |
- void discoverNewDevices(); |
|
21 |
- void connectPrinter(BluetoothDevice device); |
|
22 |
- void cancelDiscovery(); |
|
23 |
- } |
|
24 |
- |
|
25 |
- public interface View{ |
|
26 |
- void onBluetoothEnabled(); |
|
27 |
- void onBluetoothDisabled(); |
|
28 |
- void onPrinterStatusFetched(String status); |
|
29 |
- void onNewDeviceDiscovered(BluetoothDevice device); |
|
30 |
- void onPairedDeviceDiscovered(List<BluetoothDevice> devices); |
|
31 |
- void showToast(String msg); |
|
32 |
- } |
|
33 |
-} |
@@ -1,223 +0,0 @@ |
||
1 |
-package ai.pai.lensman.printer; |
|
2 |
- |
|
3 |
-import android.bluetooth.BluetoothAdapter; |
|
4 |
-import android.bluetooth.BluetoothDevice; |
|
5 |
-import android.content.BroadcastReceiver; |
|
6 |
-import android.content.ComponentName; |
|
7 |
-import android.content.Context; |
|
8 |
-import android.content.Intent; |
|
9 |
-import android.content.IntentFilter; |
|
10 |
-import android.content.ServiceConnection; |
|
11 |
-import android.os.IBinder; |
|
12 |
-import android.text.TextUtils; |
|
13 |
-import android.util.Log; |
|
14 |
- |
|
15 |
-import com.gprinter.command.GpCom; |
|
16 |
-import com.gprinter.io.GpDevice; |
|
17 |
-import com.gprinter.service.GpPrintService; |
|
18 |
- |
|
19 |
-import java.util.ArrayList; |
|
20 |
-import java.util.List; |
|
21 |
-import java.util.Set; |
|
22 |
- |
|
23 |
-import ai.pai.lensman.App; |
|
24 |
-import ai.pai.lensman.R; |
|
25 |
-import ai.pai.lensman.db.Preferences; |
|
26 |
- |
|
27 |
- |
|
28 |
-public class PrinterSettingPresenter implements PrinterSettingContract.Presenter { |
|
29 |
- |
|
30 |
- private Context context; |
|
31 |
- private PrinterService printerService; |
|
32 |
- private PrinterSettingContract.View view; |
|
33 |
- private PrinterServiceConnection connection; |
|
34 |
- private BluetoothAdapter bluetoothAdapter; |
|
35 |
- |
|
36 |
- private static final String TAG = "PrinterSettingPresenter"; |
|
37 |
- |
|
38 |
- private class PrinterServiceConnection implements ServiceConnection{ |
|
39 |
- |
|
40 |
- @Override |
|
41 |
- public void onServiceConnected(ComponentName name, IBinder service) { |
|
42 |
- printerService = ((PrinterService.PrintServiceBinder)service).getService(); |
|
43 |
- } |
|
44 |
- |
|
45 |
- @Override |
|
46 |
- public void onServiceDisconnected(ComponentName name) { |
|
47 |
- printerService = null; |
|
48 |
- } |
|
49 |
- } |
|
50 |
- |
|
51 |
- public PrinterSettingPresenter(Context context, PrinterSettingContract.View view){ |
|
52 |
- this.view = view; |
|
53 |
- this.context = context; |
|
54 |
- connection = new PrinterServiceConnection(); |
|
55 |
- bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); |
|
56 |
- } |
|
57 |
- |
|
58 |
- @Override |
|
59 |
- public void start() { |
|
60 |
- registerPrinterBroadcast(); |
|
61 |
- context.startService(new Intent(context,PrinterService.class)); |
|
62 |
- context.bindService(new Intent(context,PrinterService.class),connection,Context.BIND_AUTO_CREATE); |
|
63 |
- if(queryBluetoothStatus()){ |
|
64 |
- view.onBluetoothEnabled(); |
|
65 |
- view.onPairedDeviceDiscovered(queryPairedDevices()); |
|
66 |
- discoverNewDevices(); |
|
67 |
- if(Preferences.getInstance().isPrinterConnected()){ |
|
68 |
- view.onPrinterStatusFetched(context.getString(R.string.printer_is_connected)); |
|
69 |
- }else{ |
|
70 |
- view.onPrinterStatusFetched(context.getString(R.string.click_to_query)); |
|
71 |
- } |
|
72 |
- }else{ |
|
73 |
- view.onBluetoothDisabled(); |
|
74 |
- view.showToast(context.getString(R.string.bt_is_disabled)); |
|
75 |
- } |
|
76 |
- } |
|
77 |
- |
|
78 |
- @Override |
|
79 |
- public void stop() { |
|
80 |
- cancelDiscovery(); |
|
81 |
- context.unregisterReceiver(PrinterStatusBroadcastReceiver); |
|
82 |
- if(connection!=null){ |
|
83 |
- context.unbindService(connection); |
|
84 |
- } |
|
85 |
- } |
|
86 |
- |
|
87 |
- @Override |
|
88 |
- public void queryPrinterStatus() { |
|
89 |
- if(printerService==null){ |
|
90 |
- view.showToast(context.getString(R.string.printer_status_query_fail)); |
|
91 |
- return; |
|
92 |
- } |
|
93 |
- view.onPrinterStatusFetched(printerService.queryPrinterStatus()); |
|
94 |
- } |
|
95 |
- |
|
96 |
- |
|
97 |
- @Override |
|
98 |
- public void printQR(String qrCodeStr) { |
|
99 |
- if(printerService==null){ |
|
100 |
- view.showToast(context.getString(R.string.printer_service_boot_fail)); |
|
101 |
- return; |
|
102 |
- } |
|
103 |
- if(TextUtils.isEmpty(Preferences.getInstance().getPrinterMac())){ |
|
104 |
- view.showToast(App.getAppContext().getString(R.string.not_set_printer_yet)); |
|
105 |
- return; |
|
106 |
- } |
|
107 |
- int code = printerService.printQR(qrCodeStr); |
|
108 |
- if(code == PrinterService.ERROR_CODE_PRINTER_SERVICE_EXCEPTION){ |
|
109 |
- view.showToast(context.getString(R.string.go_check_printer)); |
|
110 |
- }else if(code == PrinterService.ERROR_CODE_PRINTER_SERVICE_OFF){ |
|
111 |
- view.showToast(context.getString(R.string.go_check_printer)); |
|
112 |
- }else if( GpCom.ERROR_CODE.values()[code]!= GpCom.ERROR_CODE.SUCCESS){ |
|
113 |
- view.showToast( GpCom.getErrorText(GpCom.ERROR_CODE.values()[code])); |
|
114 |
- } |
|
115 |
- } |
|
116 |
- |
|
117 |
- @Override |
|
118 |
- public boolean queryBluetoothStatus() { |
|
119 |
- if(bluetoothAdapter==null){ |
|
120 |
- return false; |
|
121 |
- } |
|
122 |
- return bluetoothAdapter.isEnabled(); |
|
123 |
- } |
|
124 |
- |
|
125 |
- @Override |
|
126 |
- public List<BluetoothDevice> queryPairedDevices() { |
|
127 |
- ArrayList<BluetoothDevice> pairedDevices = new ArrayList<>(); |
|
128 |
- Set<BluetoothDevice> deviceSet = bluetoothAdapter.getBondedDevices(); |
|
129 |
- for(BluetoothDevice device: deviceSet){ |
|
130 |
- pairedDevices.add(device); |
|
131 |
- } |
|
132 |
- return pairedDevices; |
|
133 |
- |
|
134 |
- } |
|
135 |
- |
|
136 |
- @Override |
|
137 |
- public void discoverNewDevices() { |
|
138 |
- // Register for broadcasts when a device is discovered |
|
139 |
- IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); |
|
140 |
- context.registerReceiver(mFindBlueToothReceiver, filter); |
|
141 |
- // Register for broadcasts when discovery has finished |
|
142 |
- filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); |
|
143 |
- context.registerReceiver(mFindBlueToothReceiver, filter); |
|
144 |
- bluetoothAdapter.startDiscovery(); |
|
145 |
- } |
|
146 |
- |
|
147 |
- @Override |
|
148 |
- public void connectPrinter(BluetoothDevice device) { |
|
149 |
- if(printerService==null){ |
|
150 |
- view.showToast(context.getString(R.string.printer_service_boot_fail)); |
|
151 |
- return; |
|
152 |
- } |
|
153 |
- int code = printerService.connectPrinter(device); |
|
154 |
- if(code==0){ |
|
155 |
- Preferences.getInstance().setPrinterMac(device.getAddress()); |
|
156 |
- Preferences.getInstance().setPrinterConnected(true); |
|
157 |
- }else{ |
|
158 |
- view.showToast(context.getString(R.string.printer_port_open_fail)); |
|
159 |
- Preferences.getInstance().setPrinterConnected(false); |
|
160 |
- } |
|
161 |
- |
|
162 |
- } |
|
163 |
- |
|
164 |
- @Override |
|
165 |
- public void cancelDiscovery() { |
|
166 |
- try{ |
|
167 |
- bluetoothAdapter.cancelDiscovery(); |
|
168 |
- context.unregisterReceiver(mFindBlueToothReceiver); |
|
169 |
- }catch (Exception e){ |
|
170 |
- e.printStackTrace(); |
|
171 |
- } |
|
172 |
- } |
|
173 |
- |
|
174 |
- |
|
175 |
- // changes the title when discovery is finished |
|
176 |
- private final BroadcastReceiver mFindBlueToothReceiver = new BroadcastReceiver() { |
|
177 |
- @Override |
|
178 |
- public void onReceive(Context context, Intent intent) { |
|
179 |
- String action = intent.getAction(); |
|
180 |
- // When discovery finds a device |
|
181 |
- if (BluetoothDevice.ACTION_FOUND.equals(action)) { |
|
182 |
- // Get the BluetoothDevice object from the Intent |
|
183 |
- BluetoothDevice device = intent |
|
184 |
- .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); |
|
185 |
- // If it's already paired, skip it, because it's been listed |
|
186 |
- // already |
|
187 |
- if (device.getBondState() != BluetoothDevice.BOND_BONDED) { |
|
188 |
- view.onNewDeviceDiscovered(device); |
|
189 |
- } |
|
190 |
- // When discovery is finished, change the Activity title |
|
191 |
- } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED |
|
192 |
- .equals(action)) { |
|
193 |
- view.showToast(context.getString(R.string.bt_discover_complete)); |
|
194 |
- } |
|
195 |
- } |
|
196 |
- }; |
|
197 |
- |
|
198 |
- private void registerPrinterBroadcast() { |
|
199 |
- IntentFilter filter = new IntentFilter(); |
|
200 |
- filter.addAction(GpCom.ACTION_CONNECT_STATUS); |
|
201 |
- context.registerReceiver(PrinterStatusBroadcastReceiver, filter); |
|
202 |
- } |
|
203 |
- |
|
204 |
- private BroadcastReceiver PrinterStatusBroadcastReceiver = new BroadcastReceiver() { |
|
205 |
- @Override |
|
206 |
- public void onReceive(Context context, Intent intent) { |
|
207 |
- if (GpCom.ACTION_CONNECT_STATUS.equals(intent.getAction())) { |
|
208 |
- int type = intent.getIntExtra(GpPrintService.CONNECT_STATUS, 0); |
|
209 |
- Log.d(TAG, "connect status " + type); |
|
210 |
- if (type == GpDevice.STATE_CONNECTING) { |
|
211 |
- view.onPrinterStatusFetched(context.getString(R.string.connecting)); |
|
212 |
- } else if (type == GpDevice.STATE_NONE) { |
|
213 |
- view.onPrinterStatusFetched(context.getString(R.string.connecting)); |
|
214 |
- } else if (type == GpDevice.STATE_VALID_PRINTER) { |
|
215 |
- view.onPrinterStatusFetched(context.getString(R.string.printer_is_connected)); |
|
216 |
- } else if (type == GpDevice.STATE_INVALID_PRINTER) { |
|
217 |
- view.onPrinterStatusFetched(context.getString(R.string.printer_is_disconnected)); |
|
218 |
- } |
|
219 |
- } |
|
220 |
- } |
|
221 |
- }; |
|
222 |
- |
|
223 |
-} |
@@ -24,7 +24,6 @@ import ai.pai.lensman.activities.SessionQRCodeActivity; |
||
24 | 24 |
import ai.pai.lensman.base.BaseActivity; |
25 | 25 |
import ai.pai.lensman.bean.PhotoBean; |
26 | 26 |
import ai.pai.lensman.bean.SessionBean; |
27 |
-import ai.pai.lensman.printer.PrinterSettingActivity; |
|
28 | 27 |
import ai.pai.lensman.qrcode.QRCaptureActivity; |
29 | 28 |
import ai.pai.lensman.utils.UmengEvent; |
30 | 29 |
import ai.pai.lensman.views.ExitSessionConfirmPopup; |
@@ -231,8 +230,6 @@ public class SessionActivity extends BaseActivity implements SessionContract.Vie |
||
231 | 230 |
Intent intent = new Intent(this,SessionQRCodeActivity.class); |
232 | 231 |
intent.putExtra("qrcode",sessionBean.sessionId); |
233 | 232 |
startActivity(intent); |
234 |
- }else if(view.getId()==R.id.tv_printer_set){ |
|
235 |
- startActivity(new Intent(this, PrinterSettingActivity.class)); |
|
236 | 233 |
}else if(view.getId()==R.id.btn_exit_session_confirm){ |
237 | 234 |
presenter.stop(); |
238 | 235 |
finish(); |
@@ -1,11 +0,0 @@ |
||
1 |
-package com.gprinter.aidl; |
|
2 |
-interface GpService{ |
|
3 |
- int openPort(int PrinterId,int PortType,String DeviceName,int PortNumber); |
|
4 |
- void closePort(int PrinterId); |
|
5 |
- int getPrinterConnectStatus(int PrinterId); |
|
6 |
- int printeTestPage(int PrinterId); |
|
7 |
- int queryPrinterStatus(int PrinterId,int Timesout); |
|
8 |
- int getPrinterCommandType(int PrinterId); |
|
9 |
- int sendEscCommand(int PrinterId, String b64); |
|
10 |
- int sendTscCommand(int PrinterId, String b64); |
|
11 |
-} |